//
//  ShopKeepingCell.m
//  tryshopping.boss
//
//  Created by Mr.Lee on 2017/3/22.
//  Copyright © 2017年 Reabam. All rights reserved.
//

#import "ShopKeepingCell.h"
#import "StaffCompListModel.h"

@interface ShopKeepingCell()

// 头像背景
@property (weak, nonatomic) IBOutlet UIView *backGroundView;
// 头像
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
// 店名
@property (weak, nonatomic) IBOutlet UILabel *stoteName;
// 说明
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
// 消息标识
@property (weak, nonatomic) IBOutlet UIView *msgIdentify;

@end

@implementation ShopKeepingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backGroundView.backgroundColor = [UIColor colorWithHexString:@"cccccc" alpha:0.24];
    self.backGroundView.layer.cornerRadius = self.backGroundView.width * 0.5;
    self.backGroundView.layer.masksToBounds = YES;
    
    self.iconView.layer.cornerRadius = self.iconView.width *0.5;
    self.iconView.layer.masksToBounds = YES;
    
    self.msgIdentify.layer.cornerRadius = self.msgIdentify.width * 0.5;
    self.msgIdentify.layer.masksToBounds = YES;
    self.msgIdentify.layer.borderWidth = 2;
    self.msgIdentify.layer.borderColor = [UIColor whiteColor].CGColor;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)setModel:(StaffCompListModel *)model{
    _model = model;

    // 头像
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.companyImg] placeholderImage:[UIImage imageNamed:@"zhengfangxing"]];

    // 店名称
    self.stoteName.text = [NSString stringWithFormat:@"%@", model.companyName];
    
    // 总人数
    NSString *totalQty = [NSString stringWithFormat:@"%@", model.totalQty];
    // 待审核认识
    NSString *totalAuditQty = [NSString stringWithFormat:@"%@", model.totalAuditQty];
    
//    NSString *countStr = [NSString stringWithFormat:@"共%@人  %@人待审核", totalQty, totalAuditQty];
    NSString *countStr = nil;
    if (totalAuditQty.intValue > 0) {
        countStr = [NSString stringWithFormat:@"共%@人  %@人待审核", totalQty, totalAuditQty];
    } else{
        countStr = [NSString stringWithFormat:@"共%@人", totalQty];
    }
    
    
    
    // 设置是否有消息
    if (totalAuditQty.intValue > 0) {
        self.msgIdentify.hidden = NO;
        self.contentLabel.textColor = [UIColor colorWithHexString:@"ff3300"];
    } else{
        self.msgIdentify.hidden = YES;
        self.contentLabel.textColor = [UIColor colorWithHexString:@"cccccc"];
    }
   
    // 设置哪个字符串
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc] initWithString:countStr];

    [AttributedStr addAttribute:NSForegroundColorAttributeName
    
                          value:COLOR(153, 153, 153)
    
                          range:NSMakeRange(0, totalQty.length+2)];
    
    // 设置文字
    self.contentLabel.attributedText=AttributedStr;
    
    
//    if (indexPath.section == 0) {
//        cell.RankingSign.image = [UIImage imageNamed:@"diyi"];
//    } else if (indexPath.section == 1){
//        cell.RankingSign.image = [UIImage imageNamed:@"dier"];
//    } else if (indexPath.section == 2) {
//        cell.RankingSign.image = [UIImage imageNamed:@"disan"];
//    } else{
//        cell.RankingSign.hidden = YES;
//    }
    

    
    
}


//实例化
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"HomeCell";
    ShopKeepingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
    }
    return cell;
}

@end
